package bravo.xc.com.xc_bravo_android.operation.withdraw.withdrawrecord;

import android.util.Log;

import bravo.xc.com.xc_bravo_android.beans.WithDrawRecordBeans;
import bravo.xc.com.xc_bravo_android.beans.WithdrawRecordResultBeans;
import bravo.xc.com.xc_bravo_android.http.HttpSingleton;
import bravo.xc.com.xc_bravo_android.http.UserOperationService;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * CREATED BY YANK
 * DATE : 2017/11/7
 * MAIL : YANK.TENYOND@GMAIL.COM
 * FUNCTION :
 */

public class WithdrawRecordPresenter extends WithdrawRecordContract.WithdrawRecordPresenter {

    private UserOperationService service = HttpSingleton.getInstance().service;
    @Override
    public void doRecord(WithDrawRecordBeans withDrawRecordBeans) {
        compositeSubscription.add(service.withDrawRecord(withDrawRecordBeans)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<WithdrawRecordResultBeans>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.e("@@onError",String.valueOf(e));
                        view.showToast("网络错误，请重试");
                    }

                    @Override
                    public void onNext(WithdrawRecordResultBeans withdrawRecordResultBeans) {
                        view.setAdapter(withdrawRecordResultBeans);
                    }
                })
        );

    }
}
